home *** CD-ROM | disk | FTP | other *** search
/ Gekikoh Dennoh Club 1 / Gekikoh Dennoh Club Vol. 1 (Japan).7z / Gekikoh Dennoh Club Vol. 1 (Japan) (Track 1).bin / kowin / archive / net / k20menus.lzh / k20menu.c < prev    next >
C/C++ Source or Header  |  1994-09-10  |  8KB  |  353 lines

  1. /*    Copyright 1992 H.Ogasawara (COR.)    */
  2. #include    <corlib.h>
  3. #include    "k20menu.h"
  4.  
  5. int    WindowHeapSize= 40*1024;
  6.  
  7. int        total;
  8. NET_MENU    *top= NULL;
  9. unsigned char    **lp= NULL;
  10. int        font= 12;
  11. int        autoexit= FALSE,
  12.         ncflag= FALSE;
  13. short        dspmode= 0,
  14.         lock= FALSE;
  15. WindowID    Awp, Bwp;
  16. NET_MENU    nnt;
  17. char        k20[]= "k20.win";
  18.  
  19. unsigned char    NetMenuFile[80],
  20.         NetLogFile[80];
  21.  
  22. unsigned char *
  23. getword( str, ptr )
  24. unsigned char    *str, *ptr;
  25. {
  26.     unsigned char    c= ' ', d= '\t';
  27.     for(; *ptr == ' ' || *ptr == '\t' ; ptr++ );
  28.     if( *ptr == '"' ){
  29.         c= '"';
  30.         d= '\n';
  31.         ptr++;
  32.     }
  33.     for(; *ptr && *ptr != c && *ptr != d && *ptr != '\n' ; *str++= *ptr++ );
  34.     *str= '\0';
  35.     if( *ptr == '"' )
  36.         ptr++;
  37.     return    ptr;
  38. }
  39.  
  40. unsigned char *
  41. ngetword( str, ptr, n )
  42. unsigned char    *str, *ptr;
  43. {
  44.     for(; n-- ; ptr= getword( str, ptr ) );
  45.     return    ptr;
  46. }
  47.  
  48. unsigned char *
  49. astrcpy( str, ptr )
  50. unsigned char    *str, *ptr;
  51. {
  52.     while( *str++= *ptr++ );
  53.     return    str;
  54. }
  55. unsigned char *
  56. astrnum( str, i, c, h )
  57. unsigned char    *str;
  58. int        i, c, h;
  59. {
  60.     unsigned char    *p= str+i;
  61.     do{
  62.         *--p= c%10+'0';
  63.     }while( c/= 10 );
  64.     while( p > str )
  65.         *--p= h;
  66.     return    str+i;
  67. }
  68.  
  69. unsigned char *
  70. fill_str( ptr, str, n )
  71. unsigned char    *ptr, *str;
  72. {
  73.     unsigned char    *lip= ptr;
  74.     ptr= astrcpy( ptr, str )-1;
  75.     for(; ptr < lip+n ; *ptr++= ' ' );
  76.     return    ptr;
  77. }
  78.  
  79. /*
  80.   ネット名              回数/今月  料金   アクセス時間  最終ログイン
  81. -----------------------------------------------------------------------0
  82. ●でんでんネット        1000/  20  1200円 00:00:00  92-08-27 00:00:00
  83. 01234567890123456789012345678901234567890123456789012345678901234567890
  84.   ()今月の合計()00-00   1000/  20  1200円 00:00:00  92-08-27 00:00:00
  85.   ()今月の合計()00-00   Key   区域  Tel
  86.             sps   隣接  !0088-011-757-4001!0088-011-736-6379
  87.   ()今月の合計()00-00   RS232C               LogFile
  88.               9600 8 N 1 X ON SJIS 
  89.   ()今月の合計()00-00     OPT モデムコマンド
  90.               00000 AT&C1\\X1
  91. */
  92. make_1line( net, ptr, m )
  93. NET_MENU    *net;
  94. unsigned char    *ptr;
  95. {
  96.     unsigned char    *lip= ptr;
  97.     int        time;
  98.     unsigned char    buf[256];
  99.     *ptr++= ('●'>>8);
  100.     *ptr++= ('●'&255);
  101.     ptr= fill_str( ptr, net->name, 24-2 );
  102. /*    ptr= astrcpy( ptr, net->name )-1;
  103.     for(; ptr < lip+24 ; *ptr++= ' ' );*/
  104.     if( m < 2 ){
  105.         ptr= astrnum( ptr, 4, net->count, ' ' );
  106.         *ptr++= '/';
  107.         ptr= astrnum( ptr, 4, net->tcount, ' ' );
  108.         ptr= astrnum( ptr, 6, m ? net->lyen : net->yen, ' ' );
  109.         *ptr++= ('円'>>8);
  110.         *ptr++= ('円'&255);
  111.         time= m ? net->ltime : net->ttime;
  112.         ptr= astrnum( ptr, 3, time/3600, ' ' );
  113.         *ptr++= ':';
  114.         ptr= astrnum( ptr, 2, (time/60)%60, '0' );
  115.         *ptr++= ':';
  116.         ptr= astrnum( ptr, 2, time%60, '0' );
  117.         *ptr++= ' ';
  118.         ptr= astrcpy( ptr, net->lastlogin );
  119.     }else if( m == 2 ){
  120.         ngetword( buf, net->line, 4 );
  121.         ptr= fill_str( ptr, buf, 6 );
  122.         ngetword( buf, net->line, 3 );
  123.         ptr= astrcpy( ptr, buf );
  124.     }else if( m == 3 ){
  125.         ngetword( buf, net->line, 6 );
  126.         ptr= fill_str( ptr, buf, 21 );
  127.         ngetword( buf, net->line, 5 );
  128.         ptr= astrcpy( ptr, buf );
  129.     }else if( m == 4 ){
  130.         ptr= fill_str( ptr, net->key, 6 );
  131.         ngetword( buf, net->line, 7 );
  132.         ptr= astrnum( ptr, 5, atoi2(buf), ' ' );
  133.         *ptr++= ' ';
  134.         ngetword( buf, net->line, 8 );
  135.         ptr= astrcpy( ptr, buf );
  136.     }else if( m == 5 ){
  137.         if( lock )
  138.             ptr= astrcpy( ptr, "<Lock>" );
  139.         else
  140.             ptr= astrcpy( ptr, ngetword( buf, net->line, 8 ) );
  141.     }
  142.     lip[70]= '\0';
  143. }
  144. static char    *title[]= {
  145. "  ネット名              回数/今月   料金  アクセス時間 最終ログイン      ",
  146. "  ネット名              回数/今月  L料金  LAST時間 LASTログイン      ",
  147. "  ネット名              区域  電話番号                               ",
  148. "  ネット名              RS232C設定           ログファイル名          ",
  149. "  ネット名              Key     OPT モデムコマンド                   ",
  150. "  ネット名              自動ログイン手順                             ",
  151. };
  152. make_line( net, lp )
  153. NET_MENU    *net;
  154. unsigned char    **lp;
  155. {
  156.     astrcpy( *lp++, title[dspmode] );
  157.     make_1line( &nnt, *lp++, 0 );
  158.     lp[-1][0]= lp[-1][1]= ' ';
  159.     for(; net ; net= net->next )
  160.         make_1line( net, *lp++, dspmode );
  161. }
  162.  
  163. NET_MENU *
  164. searchkey( key )
  165. unsigned char    *key;
  166. {
  167.     NET_MENU    *net= top;
  168.     for(; net ; net= net->next ){
  169.         if( !strcmp( key, net->key ) )
  170.             return    net;
  171.     }
  172.     return    NULL;
  173. }
  174.  
  175. /*
  176. sps|92-08-28 15:59:12-98/20
  177.    012345678901234567890123
  178. */
  179. log_count( file )
  180. unsigned char    *file;
  181. {
  182.     FILE    *fp;
  183.     unsigned char    buf[256],
  184.             key[256];
  185.     static unsigned char    dat[20+12],
  186.             *ptr, *str;
  187.     NET_MENU    *net;
  188.     astrcpy( dat, "《今月の合計》" );
  189. /*    DATEASC( (DATEBIN(BINDATEGET())&0x0fffffff)+0x30000000, dat+14 );*/
  190.     getdate( dat+14 );
  191.     dat[14+5]= '\0';
  192.     nnt.yen= nnt.tcount= nnt.ttime= 0;
  193.     *nnt.lastlogin= '\0';
  194.     nnt.name= dat;
  195.     if( fp= fopen( file, "r" ) ){
  196.         for(; fgets( ptr= buf, 256, fp ) ;){
  197.             for( str= key ; *ptr != '|' ; *str++= *ptr++ );
  198.             *str= '\0';
  199.             if( net= searchkey( key ) ){
  200.                 str= ptr;
  201.                 for(; *ptr && *ptr != ' ' ; ptr++ );
  202.                 for(; *ptr && *ptr != '-' ; ptr++ );
  203.                 if( !*ptr )
  204.                     continue;
  205.                 *ptr++= '\0';
  206.                 astrcpy( nnt.lastlogin, str+1 );
  207.                 net->ltime= atoi2( ptr );
  208.                 for(; *ptr && *ptr != '/' ; ptr++ );
  209.                 if( !*ptr )
  210.                     continue;
  211.                 net->lyen= atoi2( ptr+1 );
  212.  
  213.                 astrcpy( net->lastlogin, nnt.lastlogin );
  214.                 net->count++;
  215.                 nnt.count++;
  216.  
  217.                 if( !strncmp( nnt.lastlogin, dat+14, 5 ) ){
  218.                     net->tcount++;
  219.                     net->ttime+= net->ltime;
  220.                     net->yen+= net->lyen;
  221.                     nnt.tcount++;
  222.                     nnt.yen+= net->lyen;
  223.                     nnt.ttime+= net->ltime;
  224.                 }
  225.             }else{
  226.                 ConsoleOpen();
  227.                 ConsolePrint( key );
  228.                 ConsolePrint( ":net_menu に無いキーワードです\r\n" );
  229.             }
  230.         }
  231.         fclose( fp );
  232.     }
  233. }
  234.  
  235. read_net( file )
  236. unsigned char    *file;
  237. {
  238.     FILE        *fp;
  239.     unsigned char    rbuf[1024],
  240.             key[256],
  241.             name[256];
  242.     if( lp ){
  243.         free( lp );
  244.         lp= NULL;
  245.     }
  246.     while( top ){
  247.         NET_MENU    *net= top;
  248.         free( top->key );
  249.         top= top->next;
  250.         free( net );
  251.     }
  252.     total= 2;
  253.     ConsoleOpen();
  254.     if( fp= fopen( file, "r" ) ){
  255.         NET_MENU    *net,
  256.                 *prv= NULL;
  257.         unsigned char    *ptr;
  258.         fgets( rbuf, 1024, fp );
  259.         fgets( rbuf, 1024, fp );
  260.         for(; fgets( ptr= rbuf, 1024, fp ) ;){
  261.             int    len= strlen( rbuf );
  262.             if( *ptr == '.' )
  263.                 break;
  264.             ptr= getword( key, ptr );
  265.             ptr= getword( name, ptr );
  266.             len+= strlen(key)+strlen(name)+8;
  267.             net= (NET_MENU*)malloc( sizeof( NET_MENU ) );
  268.             if( !top )
  269.                 top= net;
  270.             if( net && (ptr= (unsigned char*)malloc( len )) ){
  271.                 ptr= astrcpy( net->key= ptr, key );
  272.                 ptr= astrcpy( net->name= ptr, name );
  273.                 ptr= astrcpy( net->line= ptr, rbuf );
  274.                 net->count= net->tcount=
  275.                 net->ltime= net->lyen=
  276.                 net->ttime= net->yen= 0;
  277.                 *net->lastlogin= '\0';
  278.                 if( prv )
  279.                     prv->next= net;
  280.                 net->next= NULL;
  281.                 prv= net;
  282.                 total++;
  283.             }else{
  284.                 ConsolePrint( "MemoryError\r\n");
  285.                 break;
  286.             }
  287.         }
  288.         fclose( fp );
  289.     }else{
  290.         ConsolePrint( file );
  291.         ConsolePrint( ":OPENできません\r\n" );
  292.     }
  293.     if( !(lp= (unsigned char**)
  294.         malloc( total*70 + sizeof( char*)*total )) ){
  295.         ConsolePrint( "MALLOC Error\r\n");
  296.         return;
  297.     }
  298.     {
  299.         int    i;
  300.         unsigned char    *ptr= (unsigned char*)lp+
  301.                     sizeof( char*)*total;
  302.         for( i= 0 ; i< total ; i++ ){
  303.             *ptr= '\0';
  304.             lp[i]= ptr;
  305.             ptr+= 70;
  306.         }
  307.     }
  308. }
  309.  
  310. NET_MENU *
  311. net_count( cn )
  312. {
  313.     NET_MENU    *net= top;
  314.     for(; net && cn-- ; net= net->next );
  315.     return    net;
  316. }
  317.  
  318. net_adial( cn )
  319. int    cn;
  320. {
  321.     EventInfo    info;
  322.     int    i;
  323.     char    combuf[30];
  324.     NET_MENU    *net= top;
  325.     net= net_count( cn );
  326.     if( net ){
  327.         ConsoleOpen();
  328.         ConsolePrint( "Dial:" );
  329.         ConsolePrint( net->name );
  330.         ConsolePrint( "\r\n" );
  331.         astrcpy( combuf, "&ac " );
  332.         strcat( combuf, net->key );
  333.         info.ComBuffer= combuf;
  334.         info.ComData= 'k20';
  335.         info.option= EventUser;
  336.         if( i= PidSearch( k20, 1 ) ){
  337.             WindowSendEventAll( i, &info );
  338.         }else{
  339.             *combuf= '"';
  340.             strcat( combuf, "\"" );
  341.             WindowLoadExec( k20, combuf, NULL, NULL );
  342.         }
  343.     }
  344. }
  345.  
  346. a_dial( a )
  347. {
  348.     net_adial( a );
  349.     if( autoexit )
  350.         WindowSendSignal( WindowProcessID, SignalKill, NULL );
  351. }
  352.  
  353.